package com.holyland.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.holyland.model.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

import static com.holyland.util.IHolylandConstants.SESSION_USER;


public class BaseAction extends ActionSupport implements ServletRequestAware, SessionAware, Preparable {				

	private static final long serialVersionUID = 2053497830125230003L;	
	
	protected static final String FWD_SUCCESS = "success";
	protected static final String FWD_ERROR = "error";	
	protected static final String FWD_INPUT = "input";
		
	protected HttpServletRequest request;
	protected Map<String, Object> session;
	
	private boolean admin;		

	public boolean isAdmin() {
		return admin;
	}

	public void setAdmin(boolean admin) {
		this.admin = admin;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
		
	}

	@Override
	public void setServletRequest(HttpServletRequest httpServletRequest) {
		this.request = httpServletRequest;		
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public Map<String, Object> getSession() {
		return session;
	}			
							
	@Override
	public void prepare() throws Exception {				
		User user = (User) session.get(SESSION_USER);
		
		if(user != null) {
			admin = user.isAdmin();
		}
	}	
}
